﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data.SqlClient;
using System.Data;

using System.Configuration;
namespace Corsat.Library.DataManager
{
    public static partial class Main
    {
        public static List<Item> GetCourseLevels(int CourseTitleId)
        {
            try
            {
                command.CommandText = StoredProcedure.sp_GetCourseLevels.ToString();
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Clear();

                command.Parameters.Add(CreateParameter("CourseTitleId", CourseTitleId));

                dtMaster = new DataTable();

                adapter.Fill(dtMaster);

                List<Item> Items = ConvertTableToSmallItems(dtMaster);

                return Items;
            }
            catch (Exception exc)
            {
                return null;
            }
        }

        public static DataTable GetAllCoursesWithDates()
        {
            try
            {
                DataSet dsCourses = GetData(StoredProcedure.sp_GetAllCoursesWithDays, null);

                if (dsCourses != null && dsCourses.Tables.Count > 0)
                    return dsCourses.Tables[0];
                else
                    return null;
            }
            catch (Exception exc)
            {
                return null;
            }
        }

        public static int GetCourseId(int CourseTitleId, int CourseLevelId)
        {
            try
            {
                command.CommandText = StoredProcedure.sp_GetCourseId.ToString();
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Clear();
                command.Parameters.Add(new SqlParameter("CourseTitleId", CourseTitleId));
                command.Parameters.Add(new SqlParameter("CourseLevelId", CourseLevelId));

                DataTable dtResults = new DataTable();

                adapter.Fill(dtResults);

                if (dtResults.Rows.Count > 0)
                    return Convert.ToInt32(dtResults.Rows[0]["CourseId"]);

                return 0;
            }
            catch (Exception exc)
            {
                return 0;
            }
        }
    }
}
